﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EventEntrance
{
    public partial class Form1 : Form
    {
        Client c;
        EventEntranceClass ee;
        DataHelper dh;
        
        public Form1()
        {
            InitializeComponent();
            dh = new DataHelper();

        }

        private void tbUserID_TextChanged(object sender, EventArgs e)
        {

        }

        private void btenter_Click(object sender, EventArgs e) //check the user id, catch the errors
        {
            try
            {
                clientId = Convert.ToInt64(textBox1.Text);
                ee = new EventEntranceClass("Music Festival", clientId,dh);
                c = ee.getClient(clientId);
                if (c == null)
                {
                    MessageBox.Show("this client does not exist");
                }
                if (c != null)                                          //show the user name and balance
                {
                    label2.Text = c.LastName + " " + c.FirstName;
                    label4.Text = "" + c.Balance;
                    btgetin.Visible = true;
                }
            }
            catch (FormatException exc) { MessageBox.Show(exc.Message); }
        }

        private void btgetin_Click(object sender, EventArgs e)
        {
            if (ee.entranceEvent(c) == true)            //get in
            {
                textBox1.Text = "";
                label2.Text = "";
                label4.Text = "";
                btgetin.Visible = false;
            }
        }

        public long clientId { get; set; }
    }
}
